Creating Triangle or Arrow Shapes with ::before and ::after in CSS
You can create triangle or arrow shapes using only CSS by leveraging pseudo-elements with borders. By setting the width and height to 0 and applying different border colors, you can make triangles pointing in various directions.
Triangles are made by setting width and height to 0 and applying border properties.
The color of the visible border determines the triangle's color; other borders are set to transparent.
Use ::before or ::after pseudo-elements to add arrows or triangles without extra HTML.
Position the pseudo-element relative to the parent element to place the arrow as needed.
In this example, the ::after pseudo-element creates a black downward-pointing arrow below the .arrow element. The arrow is formed using CSS borders and requires no extra HTML elements.
Use pseudo-elements for decorative arrows or pointers instead of adding extra HTML markup.
Adjust border sizes and colors to control the direction and appearance of the triangle.
Combine with position and transform to precisely place the arrow relative to the parent.
Test across browsers to ensure the borders render correctly for different arrow directions.
How would you create a downward-pointing arrow using only CSS pseudo-elements, and what CSS properties would you need to adjust to change its size?
If you apply a background color to the element and also try to create a triangle with borders, why might the triangle not show up as expected?
A tooltip arrow is misaligned on mobile — the triangle looks distorted. What could be causing this, and how would you debug it?
We’re using a CSS triangle as a dropdown indicator, but it flickers on scroll in Safari. What’s likely happening, and how would you fix it without switching to SVG?
We’re building a scalable icon system and considering CSS triangles for arrows instead of SVGs. What are the performance, accessibility, and maintainability tradeoffs you’d evaluate?
In a design system, we need 8 different arrow directions with varying sizes and colors. How would you structure the CSS to avoid duplication and ensure consistency across themes?
Our legacy UI relies heavily on CSS triangles for tooltips and indicators, but we're migrating to a component library with SVG icons. What’s your strategy for phasing this out without breaking existing layouts or accessibility?
Across multiple teams, we’ve seen inconsistent implementations of CSS arrows — some use borders, others use transforms or clip-path. How would you establish a cross-team standard that balances performance, maintainability, and future-proofing?